﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Elev.Farmworker.Net
{
    public class HTTPClientHelper
    {
        public string URL;

        public int Timeout = 10000;

        public string Method = "POST";

        public Encoding HttpEncoding = Encoding.UTF8;

        public string HttpRequest(string message)
        {
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(URL);

            httpWebRequest.Method = Method;
            httpWebRequest.Timeout = Timeout;
            //if (!string.IsNullOrEmpty(message))
            //{
            //    byte[] btBodys = HttpEncoding.GetBytes(message);
            //    httpWebRequest.ContentLength = btBodys.Length;
            //    httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
            //}
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream());
            string responseContent = streamReader.ReadToEnd();
            httpWebResponse.Close();
            streamReader.Close();
            httpWebRequest.Abort();

            return responseContent;
        }
    }
}
